<?php
class WorkAction extends CommonAction {
	public function data() {
		date_default_timezone_set("PRC");
		$array = array();
		$workdayObj = D('workday');
		$method = $_POST;
		$d = getcity();
		$userinfo = Session::get('userinfo');
		$uObj = new UserModel();
		switch($method['do']){
			case 'userid':
				$uObj->field('id,account,nickname as name,did');
				$dObj = new DepartmentModel();
				foreach($dObj->select() as $v)
				{
					$dlist[$v['did']] = $v;
				}
				switch($userinfo['type_id']){
					case 1:
						foreach($uObj->select() as $v){
							$v['name'] = $dlist[$v['did']]['name'].'-'.$v['name'];
							$user[] = $v;
						}
						echo json_encode($user);
					break;
					case 2:
						$map['did'] = $userinfo['did'];
						foreach($uObj->where($map)->select() as $v){
							$user[] = $v;
						}
						echo json_encode($user);
					break;
					case 3:
							$map['id'] = $userinfo['id'];
							$user[] = $uObj->where($map)->find();
							echo json_encode($user);
					break;
				}
			break;
			case 'id':
				$map['uid'] = $method['uid'];
				break;
			default:
				$map['uid'] = $userinfo['id'];
			break;
		}
		if(!$method['do'] || $method['do'] == 'id'){
			foreach($workdayObj->where($map)->select() as $v){
				$v['start'] = $v['end'] = date('Y-m-d H:i:s',$v['date']);
				$v['tg'] = $v['type'];
				$array['list'][] = $v;
			}

			echo json_encode($array);
		}

	}
	public function index() {
		$this->display();
	}

}